<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@include file="/WEB-INF/views/include/head.jsp"%>
<html>
<head>
<meta name="decorator" content="sysDefault"
	content="text/html; charset=utf-8" />
<link href="${staticPath}/lib/datetimepicker/0.0.11/css/bootstrap-datetimepicker.min.css" rel="stylesheet" type="text/css">
<link href="${staticPath}/lib/chosen/1.1.0/chosen.min.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="${staticPath}/lib/ztree/3.5/css/zTreeStyle/zTreeStyle.css" type="text/css">
<!-- 选择对话框依赖的js -->
<script src="${staticPath}/lib/ztree/3.5/js/jquery.ztree.all-3.5.js" type="text/javascript"></script>
<script src="${staticPath}/js/jquery-dialog.js" type="text/javascript"></script>
<title>编辑节点信息</title>
<script type="text/javascript">
$(function (){
	var editNodeInfos = '${editNodeInfo}';
	var defId = '${defId}';
	if(editNodeInfos) {
		var editNodeInfo = jQuery.parseJSON(editNodeInfos);
		if(editNodeInfo.editNodeIds && editNodeInfo.editNodeNames){
			var nodeIdArray = editNodeInfo.editNodeIds.split(";");
			var nodeNameArray = editNodeInfo.editNodeNames.split(";");
			for(var i = 0 ; i < nodeIdArray.length ; i++) {
				initEditNodeHtml(defId,nodeIdArray[i],nodeNameArray[i],i+1);
			}
		}
	}
});

function initEditNodeHtml(defId,nodeId,nodeName,index) {
	var tr_info = "";
	tr_info += '<input type="hidden" name="editNodeId" value="'+nodeId;
	tr_info += '"><input type="hidden" name="userId" id="userId'+index;
	tr_info += '"><div class="form-group"><label for="name"  class="col-sm-2 control-label">'+nodeName+':</label>';
	tr_info += '<div class="col-sm-4"><div class="input-group"><input type="text" class="form-control" id="userName'+index;
	tr_info += '" readonly="readonly"><span class="input-group-btn"><button class="btn btn-default btn_3" id="regionDialogMultiple'+index;
	tr_info += '" type="button">选择 </button></span></div></div></div>';
	$("#div_editNodeExecutor").append(tr_info);
	//多选对话框
	var opt = {
		service: 'selectCandidateService&defId='+defId+'&nodeId='+nodeId,
		idField: "userId"+index,
		nameField: "userName"+index,
		multiple: "true",
		title: "处理人选择对话框"
	};
	var dialog = "regionDialogMultiple"+index;
	$("#"+dialog).Dialog(opt);
}

function editNodeSubmit() {
	var editNodeIds = "";
	var userIds = "";
	var isAllset = true;
	$("input[name='editNodeId']").each(function(i,val){
		if(i == 0) {
			editNodeIds += val.value;
		} else {
			editNodeIds += ("#"+val.value);
		}
	});
	$("input[name='userId']").each(function(i,val){
		if(val.value == '') {
			isAllset = false;
		}
		if(i == 0) {
			userIds += val.value;
		} else {
			userIds += ("#"+val.value);
		}
	});
	if(isAllset) {
		window.parent.document.getElementById("editNodeIds").value = editNodeIds;
		window.parent.document.getElementById("userIds").value = userIds;
		closeWin();
	} else {
		alert("请设置所有节点处理人！");
	}
	//window.parent.document.getElementById("userOptModal").style.display = "none";
	//window.parent.document.getElementById("userOptModal").setAttribute("aria-hidden", true);
	//var divobj = $(".modal-backdrop",window.parent.document);
	//divobj.remove();
}
//关闭本窗口
function closeWin() {
	$("#userOptModal",window.parent.document).click();
}

</script>
</head>
<body>
	<div class="panel panel-default">
		<div class="panel-heading">
			<h2 class="panel-title">
				<span class="input-group-addon">编辑节点处理人</span>
			</h2>
		</div>
	 <div class="panel-body">
		   
		    <!-- 修改处理人 -->
		    <div id="div_editNodeExecutor">
		    
		    </div>
		   			
			<!-- 操作 -->
			<div class="form-group" style="text-align :center">
				<input id="btn_submit" class="btn btn-primary" type="button" value="确定" onclick="editNodeSubmit();"/>
				<input class="btn btn-default" type="button" value="取消" onclick="closeWin();"/> 
			</div>
	</div>		  		
</body>
</html>